
resolveAEP <- function(frame, vsum) {
  if (missing(frame) || missing(vsum)) stop("syntax error")
  if (class(frame) != "AEP.frame") stop("the parameter 'frame' must be of type 'AEP.frame'")
  if (is.numeric(vsum) == FALSE) stop("the parameter 'vsum' must be of type 'numeric'")  
  prob <- 0
  nb_simplex <- 0
  spx <- new("AEP.HCSimplex", array(0, c(frame@nb_var)), vsum, 1, 1)
  ListOfSimplexes <- c(spx)
  while (length(ListOfSimplexes) > 0 & nb_simplex < frame@iteration) {	  
    spx <- ListOfSimplexes[[1]]    
    if (length(ListOfSimplexes) > 1) ListOfSimplexes <- ListOfSimplexes[2:length(ListOfSimplexes)]
    else ListOfSimplexes <- NULL
    hc_full <- new("AEP.HCSimplex", spx@b, spx@h, spx@s, spx@iteration)
    prob_full <- VHmeasure(frame, hc_full)		
    nb_simplex <- nb_simplex + 1
    if (prob_full > 0) {
      hc <- new("AEP.HCSimplex", spx@b, frame@alpha * spx@h, spx@s, spx@iteration)
      prob <- prob + hc@s * VHmeasure(frame, hc)			
      nb_simplex <- nb_simplex + 1
      new.it <- spx@iteration + 1
      # Check how many new simplex can be generated without exceeding the limit frame@iteration      
      num_of_simplex <- frame@iteration - (nb_simplex + length(ListOfSimplexes))
      if (num_of_simplex > 0) {           
        for (j in 2:frame@N) {
          new.b <- spx@b + (frame@alpha * spx@h * frame@binary_matrix[j,])
          new.h <- (1 - (frame@alpha * frame@sum_ones[j])) * spx@h
          new.s <- spx@s * frame@m[j]				
          ListOfSimplexes <- c(ListOfSimplexes, new("AEP.HCSimplex", new.b, new.h, new.s, new.it))			
        }			  
      }			
    }    
  }      
  new("AEP.result", prob, vsum, nb_simplex)
} 